#pragma once

#include <vector>
#include <unordered_map>

class Channel;

class Poller {
public:
    explicit Poller();
    ~Poller();

    // 等待事件发生，返回就绪的 channel 列表
    void poll(int timeoutMs, std::vector<Channel*>& activeChannels);

    // 注册/更新 channel
    void updateChannel(Channel* channel);

    // 从 epoll 中移除 channel
    void removeChannel(Channel* channel);

private:
    void update(int operation, Channel* channel);

    int epollfd_;
    static const int kInitEventListSize = 16;
    std::vector<struct epoll_event> events_;

    // fd -> Channel 映射
    std::unordered_map<int, Channel*> channels_;
};
